package com.xn2001.dao.impl;

import com.xn2001.dao.UserDao;
import com.xn2001.entity.User;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 乐心湖 on 2020/4/15 17:28
 */
@Repository
public class UserDaoImpl implements UserDao {

    private static Map<Integer,User> userMap;

    static {
        userMap = new HashMap<>();
        userMap.put(1,new User(1,"乐心湖1",181));
        userMap.put(2,new User(2,"乐心湖2",182));
        userMap.put(3,new User(3,"乐心湖3",183));
    }
    @Override
    public Collection<User> findAll() {
        return (userMap.values());
    }

    @Override
    public User findById(Integer id) {
        return userMap.get(id);
    }

    @Override
    public void delete(Integer id) {
        userMap.remove(id);
    }

    @Override
    public void save(User user) {
        userMap.put(user.getId(),user);
    }
}
